package com.android.carson.curl;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;

import com.android.carson.curl.databinding.ActivityMainBinding;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;
    private ExecutorService task = Executors.newSingleThreadExecutor();
    private Handler handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handler = new Handler(Looper.getMainLooper());

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.testCurl.setOnClickListener(v -> task.execute(() -> {
            String result = NativeBridge.instance.httpWithCurl("https://www.baidu.com");
            handler.post(() -> {
                binding.resultText.setText(result);
            });
        }));
        binding.testJson.setOnClickListener(v -> task.execute(() -> {
            String result = NativeBridge.instance.testWithJsonCpp();
            handler.post(() -> {
                binding.resultText.setText(result);
            });
        }));

        binding.testSqlite3.setOnClickListener(v -> task.execute(() -> {
            String result = NativeBridge.instance.testSqlite3();
            handler.post(() -> {
                binding.resultText.setText(result);
            });
        }));
    }

}